<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace addons\order\user\controller;


/**
 * Description of OrderManage
 * 充值订单管理
 * @author zmh
 */
class OrderManage extends \web\user\controller\AddonUserBase{

    public function index(){
        return $this->fetch();
    }

    /**
     * 充值订单列表
     * @return array
     */
    public function loadList(){
        $keyword = $this->_get('keyword');
        $filter = '';
        if ($keyword != null) {
            $filter .= ' and m.username like \'%' . $keyword . '%\'';
        }
        $order = 'id desc';

        $m = new \addons\order\model\OrderCms();
        $total = $m->getTotal($filter);
        $rows = $m->getDataList($this->getPageIndex(),$this->getPageSize(), $filter,'',$order);
        return $this->toDataGrid($total, $rows);
    }

    
    public function loadData(){
        $id = $this->_get('id');
        $m = new \addons\order\model\OrderCms();
        $data = $m->getDetail($id);
        return $data;
    }


    public function play(){
        $this->assign('path', $this->_get('path'));
        return $this->fetch();
    }
    
    /**
     * 禁止或通过
     */
    public function changeStatus(){
        $id = $this->_get('id');
        $m = new \addons\order\model\OrderCms();
        $info = $m->getDetail($id,'id,status,phone');
        $info['status'] = $info['status']?0:1;
        $res = $m->save($info);
        if($res){
            return $this->successData();
        }else{
            return $this->failData('操作账号失败');
        }
    }
    
    public function edit(){
        $m = new \addons\order\model\OrderCms();
        if(IS_POST){
            $data = $_POST;
            $data['update_at'] = NOW_DATETIME;
            $password = $this->_post("now_password");
            if($data['id']){
                $m->save($data);
                return $this->successData();
            }else{
                $data['create_at'] = NOW_DATETIME;
                $data['video_view'] = 0;
                $m->add($data);
                return $this->successData();
            }
        }else{
            $this->assign('id', $this->_get('id'));
            $this->setLoadDataAction('loadData');
            return $this->fetch();
        }
    }


    public function del(){
        $id = intval($this->_post('id'));
        if (!empty($id)) {
            $m = new \addons\order\model\OrderCms();
            try {
                $res = $m->deleteData($id);
                if ($res > 0) {
                    return $this->successData();
                }
            } catch (\Exception $e) {
                return $this->failData($e->getMessage());
            }
        } else {
            return $this->failData('删除失败，参数有误');
        }
    }
}
